package com.example.canalclientsync.mapstruct;

import com.example.canalclientsync.canal.po.Dir;
import com.example.canalclientsync.es.document.EsModel;
import com.example.canalclientsync.es.enums.EsModelClassificationEnum;
import com.newdim.essearchinf.enums.EsModelKindEnum;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

/**
 * @author chen.cr
 * @since 2023/9/14
 */
@Mapper
public interface DirMapping {
    DirMapping INSTANCE = Mappers.getMapper(DirMapping.class);

    default EsModel dir2EsModel(Dir dir) {
        EsModel esModel = new EsModel();

        esModel.setId(dir.getId());
        esModel.setTenantId(dir.getTenantId());
        esModel.setName(dir.getName());

        esModel.setClassification(EsModelClassificationEnum.getFromDir(dir).getCode());
        esModel.setKind(EsModelKindEnum.FOLDER.getCode());
        esModel.setIsFolder(true);

        // 设置文件夹的虚拟 masterId进行文件的折叠
        esModel.setMasterId(dir.getId());

        esModel.setCreateTime(dir.getCreateTime());
        esModel.setLastUpdateTime(dir.getUpdateTime());
        esModel.setCreateUserId(dir.getCreateUserId());
        esModel.setLastUpdateUserId(dir.getUpdateUserId());

        return esModel;
    }

}
